package com.zhonghui.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhonghui.common.core.result.FwResult;
import com.zhonghui.model.OrderDetail;
import com.zhonghui.service.OrderDetailService;
import com.zhonghui.service.config.AuthUser;
import com.zhonghui.vo.OrderCreateVO;
import com.zhonghui.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping
public class OrderController {

    @Autowired
    private OrderDetailService orderDetailService;

    public FwResult get(){
        return FwResult.ok();
    }

    @PostMapping("/orders/create")
    public FwResult create(@RequestBody OrderCreateVO vo){
        orderDetailService.create(vo);
        return FwResult.ok();
    }

    @PostMapping("/order/pay")
    public FwResult pay(@RequestBody OrderCreateVO vo){
        orderDetailService.create(vo);
        return FwResult.ok();
    }

    @PostMapping("/order/pages")
    public FwResult pages(@RequestBody PageVO vo){
        IPage<OrderDetail> page = orderDetailService.lambdaQuery().eq(OrderDetail::getUserId,
                AuthUser.getUserId()).page(vo.getPage());
        return FwResult.ok(page);
    }

    @GetMapping("/order/{orderNo}")
    public FwResult orderNo(@PathVariable("orderNo") String orderNo){
        OrderDetail one = orderDetailService.lambdaQuery().eq(OrderDetail::getOrderNo, orderNo).one();
        return FwResult.ok(one);
    }

}
